package com.mdlib.droid.module.home.fragment;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.mdlib.droid.R;
import com.mdlib.droid.base.BaseAppFragment;
import com.mdlib.droid.common.JumpType;
import com.mdlib.droid.model.entity.MyEntity;
import com.mdlib.droid.module.UIHelper;
import com.mdlib.droid.module.home.adapter.MyAdapter;
import com.mdlib.droid.util.DataCleanManager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindArray;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * 作者：HQY on 2018/10/22 14:08
 * 邮箱：hqy_xz@126.com
 */

public class MyFragment extends BaseAppFragment {


    @BindView(R.id.iv_my_head)
    ImageView mIvMyHead;
    @BindView(R.id.rl_my_head)
    RelativeLayout mRlMyHead;
    @BindView(R.id.tv_my_name)
    TextView mTvMyName;
    @BindView(R.id.rv_my_bottom)
    RecyclerView mRvMyBottom;
    @BindArray(R.array.my_text)
    String[] mMys;

    private Integer[] mResId = {R.mipmap.my_buy_record, R.mipmap.my_about, R.mipmap.my_feedback,
            R.mipmap.my_score, R.mipmap.my_share, R.mipmap.my_cache};
    private List<MyEntity> mMyList = new ArrayList<>();
    private MyAdapter mMyAdapter;

    public static MyFragment newInstance() {

        Bundle args = new Bundle();

        MyFragment fragment = new MyFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_my;
    }

    @Override
    protected void initView(View rootView) {
        super.initView(rootView);

        for (int i = 0; i < mMys.length; i++) {
            MyEntity my = new MyEntity();
            my.setName(mMys[i]);
            my.setResId(mResId[i]);
            if (i == 5) {
                try {
                    my.setCache(DataCleanManager.getTotalCacheSize(getActivity()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            mMyList.add(my);
        }
        mMyAdapter = new MyAdapter(mMyList);
        mRvMyBottom.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRvMyBottom.setAdapter(mMyAdapter);
        mRvMyBottom.setNestedScrollingEnabled(false);
        mRvMyBottom.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {

            }

            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                super.onItemClick(adapter, view, position);
                switch (position) {
                    case 0:
                        UIHelper.showMyPage(getActivity(), JumpType.BUY_RECORD);
                        break;
                    case 1:
                        break;
                    case 2:
                        break;
                    case 3:
                        break;
                    case 4:
                        break;
                    case 5:
                        break;
                    default:
                        break;
                }
            }
        });

    }


    @OnClick({R.id.iv_my_head, R.id.tv_my_name})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_my_head:

                break;
            case R.id.tv_my_name:
                break;
            default:
                break;
        }
    }
}
